//
//  MyRepariDetailInfoViewController.m
//  PropertyManager
//
//  Created by TNG on 2018/7/19.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "MyRepariDetailInfoViewController.h"

@interface MyRepariDetailInfoViewController () <UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) UITableView * tableview;

@end

@implementation MyRepariDetailInfoViewController

static NSString * cellID = @"cell";
static NSString * MyRepariStateTableViewCellID = @"MyRepariStateTableViewCell";
static NSString * MyRepariContentTableViewCellID = @"MyRepariContentTableViewCell";
static NSString * MyRepariImgTableViewCellID = @"MyRepariImgTableViewCell";
static NSString * MyRepariDetailInfoTableViewCellID = @"MyRepariDetailInfoTableViewCell";
static NSString * MyRepariDetailInfoHeaderTableViewCellID = @"MyRepariDetailInfoHeaderTableViewCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creatTableview];
    [self registCell];
    [self RequestData];
}

#pragma mark - 请求数据
-(void)RequestData
{
    WeakSelf;
    NSString * urlStr = [NSString stringWithFormat:@"/rest/wxRecordController/getWxRecord?id=%@",self.repariID];
    [[HTTPClient shareClient] requestWithPath:urlStr AndReturnBlock:^(NSDictionary *dic) {
      
       
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf.tableview reloadData];
        });
    } AndFailMessage:^(NSString *message, NSString *errorCode) {
        
    }];
}

-(void)registCell
{
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
    [self.tableview registerClass:[MyRepariStateTableViewCell class] forCellReuseIdentifier:MyRepariStateTableViewCellID];
    [self.tableview registerClass:[MyRepariContentTableViewCell class] forCellReuseIdentifier:MyRepariContentTableViewCellID];
    [self.tableview registerClass:[MyRepariImgTableViewCell class] forCellReuseIdentifier:MyRepariImgTableViewCellID];
    [self.tableview registerClass:[MyRepariDetailInfoTableViewCell class] forCellReuseIdentifier:MyRepariDetailInfoTableViewCellID];
    [self.tableview registerClass:[MyRepariDetailInfoHeaderTableViewCell class] forCellReuseIdentifier:MyRepariDetailInfoHeaderTableViewCellID];
}

-(void)creatTableview{
    if (self.tableview == nil) {
        UITableView * tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, kStatusAndNavBarH, WIDTH, HEIGHT - kStatusAndNavBarH - kHomeLineH) style:UITableViewStyleGrouped];
        tableview.delegate = self;
        tableview.dataSource = self;
        if (@available(iOS 11.0, *)) {
            tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
        }
        self.tableview = tableview;
        [self.view addSubview:self.tableview];
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0)
    {
        return 65;
    }else
    {
        if (indexPath.row == 0) {
            return 82;
        }else if (indexPath.row == 1)
        {
            NSString * str = @"如果你无法简洁的表达你的想法，那只说明你还不够了解它。如果你无法简洁的表达你的想法，那只说明你还明...";
            CGFloat height = [str boundingRectWithSize:CGSizeMake(WIDTH - 40, MAXFLOAT) withTextFont:font(14)].height;
            return height;
        }
        else
        {
            return 15 + (WIDTH - 70)/4 * 2 + 10 * 1 + 13;
        }
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(section == 0)
    {
        return 5;
    }
    return 3;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return [UIView new];
    }else
    {
        UIView * bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 30)];
        bgview.backgroundColor = SFM242;
        
        UILabel * nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 5, WIDTH - 40, 20)];
        nameLabel.font = font(14);
        nameLabel.textColor = SFM153;
        nameLabel.textAlignment = NSTextAlignmentLeft;
        nameLabel.text = @"报修问题";
        [bgview addSubview:nameLabel];
        
        return bgview;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0.01;
    }else
    {
        return 30;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    //    return cell;
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            MyRepariDetailInfoHeaderTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:MyRepariDetailInfoHeaderTableViewCellID];
            return cell;
        }else
        {
            MyRepariDetailInfoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:MyRepariDetailInfoTableViewCellID];
            if(indexPath.row == 1)
            {
                cell.img.backgroundColor = SFMNavBarColor;
                cell.lineView1.hidden = NO;
                cell.timeLabel.text = @"2018-09-08 12:01";
                cell.contentLabel.text = @"维修已完成，期待您的评价。";
            }else if(indexPath.row == 2)
            {
                cell.img.backgroundColor = SFM153;
                cell.lineView.hidden = NO;
                cell.lineView1.hidden = NO;
                cell.timeLabel.text = @"2018-09-08 12:01";
                cell.contentLabel.attributedText = [NSMutableAttributedString headStr:@"维修人员【李师傅】已出发，电话：" AndMiddleStr:@"13456789012" AndFootStr:@"" AndFont:font(14) AndTextColor:SFMColor(0, 123, 226)];
            }else if(indexPath.row == 3)
            {
                cell.img.backgroundColor = SFM153;
                cell.lineView.hidden = NO;
                cell.lineView1.hidden = NO;
                cell.timeLabel.text = @"2018-09-08 12:01";
                cell.contentLabel.text = @"正在为您分配维修师傅";
            }else
            {
                cell.img.backgroundColor = SFM153;
                cell.lineView.hidden = NO;
                cell.lineView1.hidden = YES;
                cell.timeLabel.text = @"2018-09-08 12:01";
                cell.contentLabel.text = @"报修提交，待处理";
            }
            return cell;
        }
    }else
    {
        if (indexPath.row == 0) {
            MyRepariStateTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:MyRepariStateTableViewCellID];
            [cell send];
            cell.stateLabel.text = @"报修已完成";
            cell.stateLabel.textColor = SFMNavBarColor;
            return cell;
        }else if (indexPath.row == 1)
        {
            MyRepariContentTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:MyRepariContentTableViewCellID];
            [cell send];
            return cell;
        }else
        {
            MyRepariImgTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:MyRepariImgTableViewCellID];
            return cell;
        }
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
